# -*- coding:utf-8 -*-
"""Created By Corvo"""

from ...common.base import *


class GoldFrogEntity(GoldSpriteEntityBase):

    def ActiveAttack(self):
        super(GoldFrogEntity, self).ActiveAttack()

        def active():
            self.BroadcastToAllClient(ServerEvent.ServerRequestPlayMusic, {
                "entityId": self.id,
                "path": "gold_frog"
            })
            targetId = self.GetAttackTarget()
            for i in xrange(18):
                if not self.IsAlive():
                    return
                self.SetFacingEntity(targetId)
                if i >= 5:
                    self.SetForwardByKnock(0.2)
                yield 1
            # self.can_hurt = True
            for entityId in self.GetMobInRadius(2, banList=[self.id]):
                self.SetInstantDamage(entityId, self.attack)
                self.SetKnockEntityAtPos(entityId, 3, 2, height=0.5)
            # self.can_hurt = False
            yield 19
            self.TriggerResetSkill()

        self.StartCoroutine(active)

class GoldChomperEntity(GoldSpriteEntityBase):

    def ActiveAttack(self):
        super(GoldChomperEntity, self).ActiveAttack()

        def active():
            self.BroadcastToAllClient(ServerEvent.ServerRequestPlayMusic, {
                "entityId": self.id,
                "path": "fire_sloth_attack"
            })
            targetId = self.GetAttackTarget()
            for i in xrange(18):
                if not self.IsAlive():
                    return
                self.SetFacingEntity(targetId)
                if i >= 5:
                    self.SetForwardByKnock(0.2)
                yield 1
            # self.can_hurt = True
            for entityId in self.GetMobInRadius(2, banList=[self.id]):
                self.SetInstantDamage(entityId, self.attack)
                self.SetKnockEntityAtPos(entityId, 3, 2, height=0.5)
                RawEntity.AddEffect(entityId, GameEffect.POISON,1,1)
            # self.can_hurt = False
            yield 19
            self.TriggerResetSkill()

        self.StartCoroutine(active)


